import random

from blockchain.chain import Chain
from blockchain.node import Node

STATIC_NODE1 = Node(node_id=1)
STATIC_NODE2 = Node(node_id=2)
STATIC_NODE3 = Node(node_id=3)
STATIC_NODE4 = Node(node_id=4)


if __name__ == '__main__':
    # test
    data = {'content': '资金托管: TEST NODE',
              'money': 0,
              'user_id': 0,
              'mobile': 0,
              'task_id': 0,
              'extra': {}}
    for i in range(0,3):
        a = [STATIC_NODE1, STATIC_NODE2, STATIC_NODE3, STATIC_NODE4]
        rand = a.pop(random.choice([0,1,2,3]))
        new_block = rand.mine(data=data)
        rand.sync_data(new_block, a)
        print(STATIC_NODE4.get_chain()[-1] == STATIC_NODE2.get_chain()[-1])
        print(STATIC_NODE1.get_chain()[-1] == STATIC_NODE3.get_chain()[-1])
        print(STATIC_NODE2.get_chain()[-1] == STATIC_NODE3.get_chain()[-1])